package com.rain.shoppingscienceproj.ui.activity.logistics;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.rain.shoppingscienceproj.R;
import com.rain.shoppingscienceproj.http.BaseSubscriber;
import com.rain.shoppingscienceproj.http.ExceptionHandle;
import com.rain.shoppingscienceproj.http.RetrofitClient;
import com.rain.shoppingscienceproj.module.LogisticsData;
import com.rain.shoppingscienceproj.ui.activity.BaseActivity;
import com.rain.shoppingscienceproj.ui.adapter.LogisticsAdapter;
import com.rain.shoppingscienceproj.ui.utile.TitleUtils;
import com.rain.shoppingscienceproj.utils.AppManager;
import com.rain.shoppingscienceproj.utils.LoadingDialog;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LogisticsActivity extends BaseActivity {

    @BindView(R.id.tv_logistics_name)
    TextView tv_logistics_name;
    @BindView(R.id.tv_logistics_code)
    TextView tv_logistics_code;
    @BindView(R.id.recycler_view)
    RecyclerView mRecyclerView;
    @BindView(R.id.tv_no_data)
    TextView tv_no_data;
    private LogisticsAdapter adapter;
    private String orderId = "";
//    private List<LogisticsStatusData> list = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics);
        TitleUtils.TitleView(this, "物流信息");
        AppManager.getAppManager().addActivity(this);
        ButterKnife.bind(this);
        orderId = getIntent().getStringExtra("type");
        loadingDialog = new LoadingDialog(this, "正在加载...");
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new LogisticsAdapter(this);
        mRecyclerView.setAdapter(adapter);
        intData();
    }

    private void intData() {
        loadingDialog.show();
        RetrofitClient.getInstance(this)
                .createBaseApi()
                .queryordermanage(orderId, new BaseSubscriber<LogisticsData>(this) {
                    @Override
                    public void onError(ExceptionHandle.ResponeThrowable e) {
                        loadingDialog.dismiss();
                        tv_no_data.setVisibility(View.VISIBLE);
                        mRecyclerView.setVisibility(View.GONE);
                        tv_logistics_name.setText("暂无物流信息");
                        tv_logistics_code.setText("暂无订单信息");
                    }

                    @Override
                    public void onNext(LogisticsData logisticsData) {
                        super.onNext(logisticsData);
                        loadingDialog.dismiss();
                        tv_no_data.setVisibility(View.GONE);
                        mRecyclerView.setVisibility(View.VISIBLE);
                        tv_logistics_name.setText(logisticsData.expName);
                        tv_logistics_code.setText(logisticsData.number);
                        adapter.setLogisticsData(logisticsData.list);
                    }
                });

    }
}
